<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/15
 * Time: 22:17
 */

namespace App\Library\form_builder\src\traits;


trait DatePickerTrait
{
    /**
     * 日期组件
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @param string $type
     * @return DatePicker
     */
    public static function datePicker($title,$field, $value = '', $type = DatePicker::TYPE_DATE)
    {
        $datePicker = new DatePicker($title,$field, $value);
        $datePicker->type($type);
        return $datePicker;
    }

    /**
     * 单选日期
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return DatePicker
     */
    public static function date($title,$field, $value = '')
    {
        return self::datePicker($title,$field, (string)$value, DatePicker::TYPE_DATE);
    }

    /**
     * 多选日期
     *
     * @param       $field
     * @param       $title
     * @param array $value
     * @return DatePicker
     */
    public static function dateMultiple($title,$field, array $value)
    {
        $date = self::datePicker($title,$field, $value, DatePicker::TYPE_DATE);
        return $date->multiple();
    }

    /**
     * 日期区间选择
     *
     * @param        $field
     * @param        $title
     * @param string $startDate
     * @param string $endDate
     * @return DatePicker
     */
    public static function dateRange($title,$field, $startDate = '', $endDate = '')
    {
        return self::datePicker($title,$field, [(string)$startDate, (string)$endDate], DatePicker::TYPE_DATE_RANGE);
    }

    /**
     * 单选日期时间
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return DatePicker
     */
    public static function dateTime($title,$field, $value = '')
    {
        return self::datePicker($title,$field, (string)$value, DatePicker::TYPE_DATE_TIME);
    }

    /**
     * 日期时间区间选择
     *
     * @param        $field
     * @param        $title
     * @param string $startDate
     * @param string $endDate
     * @return DatePicker
     */
    public static function dateTimeRange($title,$field, $startDate = '', $endDate = '')
    {
        return self::datePicker($title,$field, [(string)$startDate, (string)$endDate], DatePicker::TYPE_DATE_TIME_RANGE);
    }

    /**
     * 选择年
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return DatePicker
     */
    public static function year($title,$field, $value = '')
    {
        return self::datePicker($title,$field,(string)$value, DatePicker::TYPE_YEAR);
    }

    /**
     * 选择月
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return DatePicker
     */
    public static function month($title,$field,$value = '')
    {
        return self::datePicker($title,$field,(string)$value, DatePicker::TYPE_MONTH);
    }
}